<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户id">
              <a-input placeholder="请输入用户id" v-model="queryParam.id"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户号">
              <j-input placeholder="请输入用户号" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="手机号">
                <j-input placeholder="请输入手机号" v-model="queryParam.phone"></j-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="真实姓名">
                <j-input placeholder="请输入真实姓名" v-model="queryParam.realName"></j-input>
              </a-form-item>
            </a-col>
            <a-col :md="11" :sm="12">
              <a-form-item label="注册时间" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
                <j-date v-model="queryParam.createTime_begin" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss" style="width:45%" placeholder="请选择开始时间" ></j-date>
                <span style="width: 10px;">~</span>
                <j-date v-model="queryParam.createTime_end" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss" style="width:45%" placeholder="请选择结束时间"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('用户表')">导出</a-button>
      <!-- 高级查询区域 -->
      <a-dropdown>
        <a-menu slot="overlay">
          <a-menu-item key="0" @click="stopstatus(0)">禁止</a-menu-item>
          <a-menu-item key="1" @click="stopstatus(1)">恢复</a-menu-item>
        </a-menu>
        <a-button type="primary" style="margin-left: 8px"> 禁止  恢复 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="status" slot-scope="text, record, index">
            <a-tag color="pink" v-if="text==0">禁用</a-tag>
            <a-tag color="#87d068" v-if="text==1" >正常</a-tag>
        </span>

        <span slot="isAuthentication" slot-scope="text, record, index">
            <a-tag color="pink" v-if="text==0">未实名</a-tag>
            <a-tag color="#87d068" v-if="text==1" >已实名</a-tag>
        </span>

        <span slot="action" slot-scope="text, record">
          <a @click="handleShow(record)" >查看</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record,1)" v-if='record.status==0'>恢复</a>
          <a @click="handleEdit(record,0)" v-if='record.status==1' style='color: red'>禁止</a>
        </span>

      </a-table>
    </div>

    <userhome-modal ref="modalForm" @ok="modalFormOk"></userhome-modal>
    <userhome-info-detail-modal ref="userhomeInfoDetail"></userhome-info-detail-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import UserhomeModal from './modules/UserhomeModal'
  import { putAction } from '@api/manage'
  import UserhomeInfoDetailModal from '@views/gongqiang/modules/UserhomeInfoDetailModal.vue'

  export default {
    name: 'UserhomeList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      UserhomeInfoDetailModal,
      UserhomeModal
    },
    data () {
      return {
        description: '用户表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'用户id',
            align:"center",
            dataIndex: 'id'
          },
          {
            title:'用户邮箱',
            align:"center",
            dataIndex: 'username'
          },
          {
            title:'手机号',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'真实姓名',
            align:"center",
            dataIndex: 'realName'
          },
          {
            title:'注册时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status',
            scopedSlots: { customRender: 'status' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/gongqiang/userhome/list",
          delete: "/gongqiang/userhome/delete",
          deleteBatch: "/gongqiang/userhome/deleteBatch",
          exportXlsUrl: "/gongqiang/userhome/exportXls",
          importExcelUrl: "gongqiang/userhome/importExcel",
          stopstatus:'/gongqiang/userhome/stopstatus',

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      handleEdit(record,status)
      {
        if(!this.url.stopstatus){
          this.$message.error("请设置url.stopstatus!")
          return
        }
          var ids = record.id;
          var that = this;
          this.$confirm({
            title: "确认操作",
            content: "是否操作选中数据?",
            onOk: function () {
              that.loading = true;
              putAction(that.url.stopstatus, {ids: ids,status:status}).then((res) => {
                if (res.success) {
                  //重新计算分页问题
                  that.reCalculatePage(that.selectedRowKeys.length)
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
      },
      stopstatus: function (key) {
        if(!this.url.stopstatus){
          this.$message.error("请设置url.stopstatus!")
          return
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          this.$confirm({
            title: "确认操作",
            content: "是否操作选中数据?",
            onOk: function () {
              that.loading = true;
              putAction(that.url.stopstatus, {ids: ids,status:key}).then((res) => {
                if (res.success) {
                  //重新计算分页问题
                  that.reCalculatePage(that.selectedRowKeys.length)
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        }
      },
      handleShow(row)
      {
        this.$refs.userhomeInfoDetail.show(row);
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'userhomeId',text:'用户id',dictCode:''})
        fieldList.push({type:'string',value:'username',text:'用户号',dictCode:''})
        fieldList.push({type:'string',value:'phone',text:'手机号',dictCode:''})
        fieldList.push({type:'string',value:'realName',text:'真实姓名',dictCode:''})
        fieldList.push({type:'int',value:'status',text:'状态（0禁止 1正常）',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>